﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Audio;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.GamerServices;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Media;
//using System.Threading;
//using JigLibX.Physics;
//using JigLibX.Collision;
//using JigLibX.Geometry;
//using Microsoft.Xna.Framework.Input.Touch;
//using XNAGame.Menu;
//using Services;
//using Utilities;

//namespace XNAGame.Logic.SampleLevel
//{
//  using Nuke = Projectile;
//  using NukeData = ProjectileData;

//  public class SkirmishMode : GamePlayLayer
//  {
//    int wave_destroyed;
//    int enemies_n;

//    public SkirmishMode(Game game, BaseLevelStats current_score, ShipType player_ship, int num_lives, int enemies_n, int wave_left, bool spawn_boss)
//      : base(game, current_score, player_ship, num_lives)
//    {
//      wave_destroyed = 0;
//      this.wave_left = wave_left;
//      this.spawn_boss = spawn_boss;
//      this.enemies_n = enemies_n;
//    }

//    protected override void start_level()
//    {
//      /// Inizializziamo la fisica.
//      physics = new PhysicsSystem()
//      {
//        CollisionSystem = new CollisionSystemSAP() { UseSweepTests = true },
//        Gravity = Vector3.Zero,

//        NumCollisionIterations = 2, //8
//        NumContactIterations = 2, //8
//        NumPenetrationRelaxtionTimesteps = 5, //15
//      };

//      StructAllocatorManager.Reset();
//      var sh = ConfigurationService.GetDefaulConfiguration().Ships[(int)player_ship_type].MaxShield;

//      CurrentState = new State()
//      {
//        asteroids = new ArrayList<Asteroid>(35),
//        enemies = new ArrayList<Ship>(15),
//        bosses = new ArrayList<Ship>(5),
//        primary_weapons = new ArrayList<Projectile>(100),
//        secondary_weapons = new ArrayList<Nuke>(25),
//        shockwaves = new ArrayList<ShockWave>(5),
//        bonuses = new ArrayList<Bonus>(5),
//        player = new PlayerShip()
//        {
//          AsShip = CreateShip(Vector3.Zero, scene_service[player_ship_type].BoundingSphere, 20000.0f,
//            player_ship_type, Faction.Player, 3),
//          warp_type = WarpType.None,
//          num_lives = current_score.NumLivesRemaining,
//          shield = sh,
//          energy = 1.0f,
//          warp_state = 10,  // da modificare
//          waypoint = new MaybeWaypoint() { HasValue = false, Position = Vector3.Zero },
//          age = 0.0f,
//          INVULNERABILITY_SPAWN_TIME = 3.0f,
//          shields_spawn_time = new float[] { 0, 0, 0, 0 }
//        }
//      };
//      CurrentState.enemies = generate_enemies(enemies_n, Vector3.Zero);
//      scene_bs = SceneBoundingSphere;

//      NewExplosions = new ArrayList<Explosion>(25);
//      NewShockWaves = new ArrayList<ShockWave>(5);
//      effects_manager = Game.Services.GetService(typeof(EffectsManager)) as EffectsManager;

//      LoadingScreen.LoadProccesComplete(Game);
//    }


//    public override void Update(GameTime gameTime)
//    {
//      var dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
//      for (int i = 0; i < current_targets.Count; i++)
//      {
//        var target = current_targets[i];
//        var w = target.weapon_index; 
//        if (target.StillValid == false)
//        {
//          current_targets.RemoveAt(i);
//          i--;
//          continue;
//        }

//        target.shooting_timer += dt;
//        if (target.keep_shooting && target.shooting_timer > w.FireRate)
//        {
//          var user = CurrentState.player.AsShip;
//          ShootWeapon(w.Type, user, 
//            target.target_ship, Vector3.Zero, Vector3.Zero,
//            target.target_nuke, target.target_bonus,
//            target.target_type);
//          target.shooting_timer = 0.0f;
//        }
//        current_targets[i] = target;
//      }

//      if (CurrentState.enemies.Count <= 0 && CurrentState.bosses.Count <= 0 && enemy_to_add <= 0)
//        if (wave_left <= 0)
//        {
//          if (enemy_to_add <= 0)
//            LevelWon();
//        }
//        else
//        {
//          wave_destroyed++;
//          enemy_to_add = enemies_n;
//          enemy_spawn_timer = 0.0f;

//          wave_left--;
//        }

//      if (enemy_to_add > 0)
//      {
//        enemy_spawn_timer += dt;
//        if (enemy_spawn_timer >= enemy_spawn_delay)
//        {
//          Ship ship_to_add = spawn_boss && wave_left == 0 ? generate_new_boss(ShipType.Boss1) : generate_new_enemy((ShipType)((int)ShipType.EnemyFrigate + random.Next(5)));
//          if (spawn_boss && wave_left == 0)
//          {
//            CurrentState.bosses.Add(ship_to_add);
//            enemy_to_add = 1;
//          }
//          else
//            CurrentState.enemies.Add(ship_to_add);
//          warps.Add(new EffectsManager.EnemyWarp(effects_manager, ship_to_add));
//          enemy_to_add--;
//          enemy_spawn_timer = 0;

//          //if (enemy_to_add == 0)
//          //    GC.Collect();
//        }
//      }

//      for (int j = 0; j < warps.Count; j++)
//        if (warps[j].warping_out_timer < 0)
//        {
//          warps.Remove(warps[j]);
//          warps[j].particle.IsActive = false;
//          j--;
//        }
//        else
//          warps[j].Update(dt);

//      if (CurrentState.player.stats.CurrentLife <= 0.0f || (CurrentState.enemies.Count <= 0 &&
//          CurrentState.bosses.Count <= 0 && enemy_to_add <= 0))
//        this.Enabled = false;

//      // Aggiorniamo il timer di slow-motion
//      CurrentState.slow_motion_timer = Math.Max(0.0f, CurrentState.slow_motion_timer -
//      (float)gameTime.ElapsedGameTime.TotalSeconds);

//      base.Update(gameTime);
//    }
//  }
//}
